package com.nowcoder.community.controller;

import com.nowcoder.community.util.CommunityUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>Title: AlphaController</p>
 * <p>author 12427</p>
 *
 * @version ver1.0
 * @date 2022/6/30 23:36
 */


@Controller
@RequestMapping("/alpha")  // spring mvc的注解
public class AlphaController {

    @RequestMapping("/hello")
    @ResponseBody
    public String  sayHello(){
        return "Hello Spring Boot" ;
    }


    @RequestMapping("cookie/set")
    @ResponseBody
    public String setCookie(HttpServletResponse response){
        Cookie cookie = new Cookie("code", CommunityUtil.generateUUID());
        cookie.setPath("community/alpha/cookie");
        cookie.setMaxAge(60*10);
        response.addCookie(cookie);
        return "set cookie" ;
    }


    @RequestMapping("cookie/get")
    @ResponseBody
    public String getCookie(@CookieValue("code") String code){
        System.out.println(code);
        return "get cookie" ;
    }

}

